import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
            path: '/',
            redirect: "index"
        },
        {
            path: '/Home',
            name: 'Home',
            component: function() {
                return import ( /* webpackChunkName: "Home" */ '../views/Home.vue')
            },
            children: [{
                    path: '/index',
                    name: 'index',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/Index/Index.vue') }
                },
                {
                    path: '/goods',
                    name: 'goods',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/Index/goods.vue') }
                },
                {
                    path: '/about',
                    name: 'about',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/Index/about.vue') }
                },
                {
                    path: '/details',
                    name: 'details',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/Index/details.vue') }
                },
                {
                    path: '/error',
                    name: 'error',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/Home/error.vue') }
                },
                {
                    path: '/collect',
                    name: 'collect',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/combination/collect.vue') }
                },
                {
                    path: '/order',
                    name: 'order',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/combination/order.vue') }
                },
                {
                    path: '/shoppingCart',
                    name: 'shoppingCart',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/combination/shoppingCart.vue') }
                },
                {
                    path: '/confirmOrder',
                    name: 'confirmOrder',
                    component: function() { return import ( /* webpackChunkName: "Home" */ '../components/combination/confirmOrder.vue') }
                },

            ]
        },

    ]
    //控制台会报[NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}]。其原因在于Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数，错误信息就会交给全局的路由错误处理，因此就会报上述的错误。
    //禁止全局路由错误处理打印，这个也是vue-router开发者给出的解决方案：
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
};

const router = new VueRouter({
    routes
})

export default router